<template>
	<!-- 我的收藏 -->
	<view class="notice-list">
		<view v-if="isnull" class="is--tag">暂无记录哦~</view>

		<div style="padding: 15px 10px;">
			<view v-for="notice in notices" :key="notice.activityId" class="notice-item"
				@click="xXNRorYy(notice.jzidorid,notice.type)">
				<div class="notice-title">{{ notice.title }}</div>
				<div class="notice-date">
					<text style="margin-right: 10px;font-weight: bold;">{{notice.type}}</text>
					{{ notice.adate }}
					<div class="notice-image" @tap.stop="del(notice.activityId)">
						<image src="/static/seek/aa.png" class="notice-img"></image>删除
					</div>
				</div>
			</view>
		</div>
		<view>
			<!-- 提示窗示例 -->
			<uni-popup ref="alertDialog" type="dialog">
				<uni-popup-dialog cancelText="取消" confirmText="确定" title=" " content="您确认删除?" @confirm="dialogConfirm"
					@close="dialogClose"></uni-popup-dialog>
			</uni-popup>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		onMounted,
		useCssVars
	} from 'vue';
	import {
		gonavigateTo,
		goswitchTab
	} from '@/request/wx.js';
	import {
		getActivitiesById,
		deleteActivitiesById
	} from '@/request/api.js';
	import {
		// onLoad,
		onShow
	} from '@dcloudio/uni-app';

	const token = ref(null);
	const notices = ref(null);
	const alertDialog = ref(null);
	const deleteid = ref(null);
	const isnull = ref(false);

	// 页面显示时执行的逻辑
	onShow(() => {
		console.log('页面显示时加载');
		getToken();
		showAll();
	});

	const showAll = async () => {
		// console.log("showAll");
		const userInfoRes = await getActivitiesById({
			uid: token.value,
			status: 1
		});
		// console.log(userInfoRes);
		// notices.value = userInfoRes.data.data;
		// console.log(userInfoRes.data.data.length);
		if (userInfoRes.data.data.length === 0) {
			console.log("暂无记录哦~")
			isnull.value = true;
			notices.value = '';
		} else {
			notices.value = userInfoRes.data.data;
		}
	};

	const getToken = () => { // 获取本地存储的token
		const storedToken = uni.getStorageSync('token');
		token.value = storedToken || '';
	};

	// 定义点击事件处理函数
	const xXNRorYy = (id, type) => {
		console.log(`按钮被点击了：${type},id:${id}`);
		switch (type) {
			case '家政预约':
				gonavigateTo(`/pages/user/details/details?id=${id}&type=${type}`);
				break;
			case '服务介绍':
				gonavigateTo(`/pages/user/index/xxnr?id=${id}&type=${type}`);
				break;
			case '最新动态':
				gonavigateTo(`/pages/user/index/xxnr?id=${id}&type=${type}`);
				break;
			default:
				break;
		}
	};

	const del = (id) => {
		alertDialog.value.open();
		deleteid.value = id;
		console.log(`删除：${id}`);
	};
	const dialogConfirm = () => {
		console.log('点击确认' + deleteid.value);
		deleteActivitiesById({
			aid: deleteid.value
		}).then((res) => {
			console.log(res);
			const ress = res.data;
			if (ress.code === 200) {
				console.log(ress.msg);
				showAll();
			} else {
				console.log(ress.msg);
			}
		});
	};
	const dialogClose = () => {
		console.log(`点击取消`);
	};
</script>

<style scoped>
	.is--tag {
		color: gray;
		text-align: center;
		width: 100%;
		margin-top: 30px;
		font-size: 18px;
	}

	.notice-list {
		display: flex;
		flex-direction: column;
		width: 100%;
		min-height: 100vh;
		background-color: #efefef;
	}

	.notice-item {
		margin-bottom: 30rpx;
		/* height: 190px; */
		border-radius: 22rpx;
		background-color: white;
		padding: 0px 20px;
		box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
	}

	.notice-title {
		padding: 15px 0px;
		font-size: 17px;
	}

	.notice-content {
		font-size: 15px;
	}

	.notice-date {
		color: #999;
		font-size: 12px;
		padding-bottom: 10px;
		display: flex;
		height: 25px;
		align-items: center;
	}

	.notice-img {
		width: 15px;
		height: 15px;
	}

	.notice-image {
		display: flex;
		align-items: center;
		color: red;
		margin-left: 35px;
		padding: 5px 5px;
	}
</style>